function getIndexToIns(arr, num) {
    // Find my place in this sorted array.
    arr.sort((a, b) => a - b);
    let result = arr.findIndex(item => item > num);
    if (result < 0) return arr.length;
    return arr[result - 1] === num ? result - 1 : result;
}

getIndexToIns([40, 60], 50);
